import { loadEnv, defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
import Components from 'unplugin-vue-components/vite'
import AutoImport from 'unplugin-auto-import/vite'
import {
  VantResolver,
  VueUseComponentsResolver,
} from 'unplugin-vue-components/resolvers'
import UnoCSS from 'unocss/vite'

import { resolve } from 'path'
import { ljResolver } from 'lj-utils/resolver'

const { DEV_HI } = loadEnv('dev', process.cwd(), 'DEV')
console.log(DEV_HI)
const plugins = [
  vue(),
  vueJsx(),
  UnoCSS(),
  Components({
    resolvers: [VantResolver(), VueUseComponentsResolver()],
  }),
  AutoImport({
    include: [
      /\.[tj]sx?$/, // .ts, .tsx, .js, .jsx
      /\.vue$/,
      /\.vue\?vue/, // .vue
    ],
    imports: [
      // 插件预设支持导入的api https://github.com/unjs/unimport/tree/main/src/presets
      'vue',
      '@vueuse/core',
    ],
    resolvers: [VantResolver(), ljResolver()],
    dts: true,
  }),
]
const server = {
  host: '0.0.0.0',
  port: 3001,
  proxy: {
    // '/api': 'http://api.beehub.paradeum.com:8110',
    // '/static': 'http://api.beehub.paradeum.com:8110'
  },
  headers: {
    dev: 'true',
  },
}
// https://vitejs.dev/config/
export default defineConfig({
  plugins,
  resolve: {
    alias: {
      '@': resolve(__dirname, 'src'),
    },
  },
  server,
  css: {
    preprocessorOptions: {
      scss: {
        additionalData: '@import "lj-utils/scss/global.scss";',
      },
    },
  },
})
